﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;
using CommonFunc;

public partial class Control_NewsList1 : System.Web.UI.UserControl
{
    MODEL.NewsClass MNC = new MODEL.NewsClass();
    MODEL.NewsClass _MNC = new MODEL.NewsClass();

    BLL.NewsClass BNC = new BLL.NewsClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        ControlDataInit();
    }

    protected void ControlDataInit()
    {
        try
        {
            string SQLstr;

            if (Request.QueryString["ClassID"] == null)
            {
                SQLstr = "SELECT News.*,NewsClass.NC_Title FROM ([News] INNER JOIN [NewsClass] ON News.News_ClassID = NewsClass.NC_ID) ";
                SQLstr += " WHERE [News_IsLock]=false AND [News_IsDel]=false AND [NewsClass.NC_IsLock] = false ORDER BY [News_DateTime] DESC";
            }
            else
            {
                MNC.NC_ID = Convert.ToInt32(Request.QueryString["ClassID"]);
                _MNC = BNC.GetDataByID(MNC);

                SQLstr = "SELECT * FROM [News] ";
                SQLstr += " WHERE [News_ClassCode] LIKE '" + _MNC.NC_ClassCode + "%' AND [News_IsLock]=False AND [News_IsDel]=False ORDER BY [News_DateTime] DESC";
            }

            DataTable DT_NewsList1 = AccHelper.GetDataTable(SQLstr);
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            AspNetPager1.RecordCount = DT_NewsList1.Rows.Count;
            pds.PageSize = AspNetPager1.PageSize;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.DataSource = DT_NewsList1.DefaultView;
            RPT_NewList1.DataSource = pds;
            RPT_NewList1.DataBind();
        }
        catch (Exception ex)
        {
            LB_NewsList1.Text = ex.Message;
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        ControlDataInit();
    }
}
